<template>
    <div style="display: flex;flex-direction: row;">
        <div style="width: 40%">
            <el-card style=" margin: 10px" >
                <span style="font-weight: bold ;color: seagreen">完善信息</span>
                <el-form ref="form" :model="form" label-width="80px" >
                    <el-form-item style="text-align: center" label-width="0" >
                        <el-upload
                                class="avatar-uploader"
                                :action="'http://' + serverIp +':9090/files/upload'"
                                :show-file-list="false"
                                :on-success="handleAvatarSuccess"
                        >
                            <img v-if="form.avatar" :src="form.avatar" class="avatar">
                            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                        </el-upload>
                    </el-form-item>
                    <el-form-item label="用户名">
                        <el-input v-model="form.username" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="昵称">
                        <el-input v-model="form.nick"></el-input>
                    </el-form-item>
                    <el-form-item label="年龄">
                        <el-input v-model="form.age"></el-input>
                    </el-form-item>
                    <el-form-item label="性别">
                        <el-input v-model="form.sex"></el-input>
                    </el-form-item>
                    <el-form-item label="地址">
                        <el-input v-model="form.address"></el-input>
                    </el-form-item>

                </el-form>
                <div style="text-align: center">

                    <el-button type="primary" @click="update">保存</el-button>
                </div>

            </el-card>


        </div>

        <el-divider direction="vertical"></el-divider>
        <div style="margin-left: 100px;margin-top: 20px">
            <span style="font-weight: bold;color: deepskyblue;">我的文案</span>
            <div style="margin-top: 20px">
                <span>雨纷纷</span>
                <el-divider direction="vertical"></el-divider>
                <span>旧故里</span>
                <el-divider direction="vertical"></el-divider>
                <span>草木深</span>
            </div>
            <div style="margin-top: 60px">
                <span>头上一片晴天，心中一个想念</span>
                <el-divider content-position="left">少年包青天</el-divider>
                <span>拿得起，放得下，路在脚下往前跨。没有过不去的坎，只有放不下的人</span>
                <el-divider><i class="el-icon-mobile-phone"></i></el-divider>
                <span>为了无法计算的价值</span>
                <el-divider content-position="right">阿里云</el-divider>
                <span>没必要刻意遇见谁，也不急于遇见谁，更不勉强留住谁，一切顺其自然，最好的自己留给值得珍惜的人</span>
                <el-divider content-position="left">公子无双</el-divider>
                <span> 遇见的人多了，你才会明白哪些人值得用生命去珍惜，哪些人只适合绕道而行</span>
                <el-divider content-position="right">无名</el-divider>
            </div>
        </div>


    </div>
</template>

<script>
    import request from "@/utils/request";
    import {serverIp} from "../../public/config";

    export default {
        name: "Person",
        data() {
            return {
              serverIp:serverIp,
                form: {},
                bookList: [],
                total:1
            }
        },
        created() {
            let str = sessionStorage.getItem("user") || "{}"
            this.form = JSON.parse(str)
            this.loads()
        },
        methods: {
            loads() {
                request.get("/user/selectBook", {
                    params: {
                        pageNum: this.currentPage,
                        pageSize: this.pageSize,
                        status: this.status
                    }

                }).then(res => {
                    console.log(res.data)
                    this.tableData = res.data.records
                    this.total = res.data.total
                })
            },

            handleAvatarSuccess(res) {
                this.form.avatar = res.data

                this.update()
            },
            update() {
                request.put("/user/updateUser", this.form).then(res => {
                    console.log(res)
                    if (res.code === '0') {
                        this.$message({
                            type: "success",
                            message: "更新成功"
                        })
                        sessionStorage.setItem("user", JSON.stringify(this.form))
                        // 触发Layout更新用户信息
                        this.$emit("userInfo")
                    } else {
                        this.$message({
                            type: "error",
                            message: res.msg
                        })
                    }
                })
            }
        }
    }
</script>

<style>
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 120px;
        height: 120px;
        line-height: 120px;
        text-align: center;
    }

    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
</style>
